package org.huntaway.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestFilter implements Filter {

	public void destroy() {

	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) {
		HttpServletRequest httpRequest = (HttpServletRequest) request;
		HttpServletResponse httpResponse = (HttpServletResponse) response;
		
		log(httpRequest.getRequestURI() + ":" + httpRequest.getRemoteHost()
				+ ":" + httpRequest.getLocalAddr());
		try {
			httpRequest.setCharacterEncoding("UTF-8");
			httpResponse.setCharacterEncoding("UTF-8");
			chain.doFilter(request, response);
		} catch (IOException e) {
		} catch (ServletException e) {
		}
	}

	private void log(String str) {
		System.out.println(str);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		log(RequestFilter.class.getName() + " init is run...");
	}
}
